package niuke;

public class Solution11{
    //中序遍历
    public boolean isValidBST (TreeNode root) { 
        if(root == null) return true;
        return midOrder(root);
    }
    int pre = Integer.MIN_VALUE;
    boolean midOrder( TreeNode root){
        //递归终止条件
        if(root == null) return true;
        //判断左子树
        if(!midOrder(root.left)) return false;
        //如果当前节点小于等于前一个, 说明不是
        if( root.val <= pre){
           return false; 
        } 
         pre = root.val;
        return midOrder(root.right);

    }
}
